<?php
declare(strict_types=1);
namespace app\admin\controller;
use app\facade\Basic;
use app\admin\service\ModelInfo as ServiceModelInfo;
use think\Request;

/**
 *  机型管理
 */
class ModelInfo extends Base
{

    /**
     *  机型列表
     */
    public function getList(Request $request)
    {
        $param['model_name'] = $request->param('model_name',null);
        $param['pageIndex'] = $request->param('pageIndex',1);
        $param['pageSize'] = $request->param('pageSize',50);
        $param['model_name'] = trim($param['model_name']);
        /* 验证 */
        $this->validateData($param,'ModelInfo.getList');

        $serviceRetrieve = new ServiceModelInfo();
        $result = $serviceRetrieve->getList($param);
        return Basic::json($result);
    }


    /**
     *  添加机型
    */
    public function save(Request $request)
    {
        $param['operator_id'] = $request->operator_id;
        $param['model_name'] = $request->param('model_name',null);

        $param['latest_firmware_version'] = $request->param('latest_firmware_version',null);
        $param['firmware_url'] = $request->param('firmware_url',null);

        /* 验证 */
        $this->validateData($param,'ModelInfo.save');

        $serviceRetrieve = new ServiceModelInfo();
        $result = $serviceRetrieve->save($param);
        return Basic::json($result);
    }


    /**
     *  获取详情
    */
    public function detail(Request $request)
    {
        $param['operator_id'] = $request->operator_id;
        $param['id'] = $request->param('id',null);
        /* 验证 */
        $this->validateData($param,'ModelInfo.detail');

        $serviceRetrieve = new ServiceModelInfo();
        $result = $serviceRetrieve->detail($param);
        return Basic::json($result);
    }

    /**
     *  修改机型
    */
    public function update(Request $request)
    {
        $param['operator_id'] = $request->operator_id;
        $param['id'] = $request->param('id',null);
        $param['model_name'] = $request->param('model_name',null);

        $param['latest_firmware_version'] = $request->param('latest_firmware_version',null);
        $param['firmware_url'] = $request->param('firmware_url',null);

        /* 验证 */
        $this->validateData($param,'ModelInfo.update');

        $serviceRetrieve = new ServiceModelInfo();
        $result = $serviceRetrieve->update($param);
        return Basic::json($result);
   }

    /**
     *  删除机型
    */
    public function delete(Request $request)
    {
        $param['operator_id'] = $request->operator_id;
        $param['ids'] = $request->param('ids',null);

        /* 验证 */
        $this->validateData($param,'ModelInfo.delete');

        $serviceRetrieve = new ServiceModelInfo();
        $result = $serviceRetrieve->delete($param);
        return Basic::json($result);
    }



}
